package com.cc.openeye.dynamic.kuikly.recommend.items.banner

import com.cc.openeye.dynamic.recommend.entity.dynamicResponse.ItemX
import com.tencent.kuikly.core.base.Color
import com.tencent.kuikly.core.base.ComposeView
import com.tencent.kuikly.core.base.ComposeAttr
import com.tencent.kuikly.core.base.ComposeEvent
import com.tencent.kuikly.core.base.ViewBuilder
import com.tencent.kuikly.core.base.ViewContainer
import com.tencent.kuikly.core.views.Image
import com.tencent.kuikly.core.views.compose.SliderPage

internal class InternalBannerItemView :
    ComposeView<InternalBannerItemViewAttr, InternalBannerItemViewEvent>() {

    override fun createEvent(): InternalBannerItemViewEvent {
        return InternalBannerItemViewEvent()
    }

    override fun createAttr(): InternalBannerItemViewAttr {
        return InternalBannerItemViewAttr()
    }

    override fun body(): ViewBuilder {
        val ctx = this
        return {
            SliderPage {
                attr {
                    isHorizontal = true
                    pageItemWidth = ctx.attr.flexNode?.styleWidth ?: 0f
                    pageItemHeight = ctx.attr.height

                    initSliderItems(ctx.attr.itemList ?: emptyList()) { item ->

                        attr {
                            borderRadius(8f)
                        }

                        Image {
                            attr {
                                backgroundColor(Color(0Xfff5f5f5))
//                                src(item.data?.image ?: "")
                                src("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage109.360doc.com%2FDownloadImg%2F2025%2F04%2F0321%2F296122601_4_20250403090445718&refer=http%3A%2F%2Fimage109.360doc.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1762075306&t=4fb06cdc28e2fa0d520abb8bde622c85")

                            }
                        }
                    }
                }

            }
        }
    }
}


internal class InternalBannerItemViewAttr : ComposeAttr() {
    var itemList: List<ItemX>? = null
    var height: Float = 0f
    var width: Float = 0f
}

internal class InternalBannerItemViewEvent : ComposeEvent() {

}

internal fun ViewContainer<*, *>.BannerItemView(init: InternalBannerItemView.() -> Unit) {
    addChild(InternalBannerItemView(), init)
}